from django.shortcuts import render
from product.models import Category
from product.serializers import CategorySerializer
from rest_framework import permissions, viewsets

from django.http import HttpResponse
from django.http import JsonResponse

#Create your views here.

#视图集
class CategoryViewSet(viewsets.ReadOnlyModelViewSet):
    """
      此视图自动提供`list`和`detail`操作。
    """
    queryset = Category.objects.all()[0:5]
    serializer_class = CategorySerializer

# class CategoryViewSet(viewsets.ModelViewSet):
#     queryset = Category.objects.all()[0:5]
#     serializer_class = CategorySerializer

# def detail(request,id):
#     queryset = Category.objects.filter(id=f'{id}')
#
#     #return HttpResponse(queryset)
#     return JsonResponse({"data":queryset},safe=False)
#
# def test():
#     return JsonResponse({'foo': 'bar'})